package com.gams.device.print_jna;

import com.caysn.autoreplyprint.AutoReplyPrint;
import com.gams.common.DateUtils;
import com.sun.jna.Pointer;
import com.sun.jna.WString;

public class PrintCP
{


    public static int printNumber(String projectName, String qrcodeUrl, String userName, String cardid, String queueName, String number, String tips)
    {
        String name = "VID:0x4B43,PID:0x3830";
        Pointer h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb(name, 1);
        PrintCP function = new PrintCP();
        function.Test_Pos_SampleTicket_80MM_1(h, projectName, qrcodeUrl, userName, cardid, queueName, number, tips);
        return 0;
    }

    void Test_Pos_SampleTicket_80MM_1(Pointer h, String title, String qrcodeUrl, String userName, String cardid, String queueName, String number, String tips)
    {
        int[] nLineStartPos = {0, 201, 401};
        int[] nLineEndPos = {200, 400, 575};

        {
            AutoReplyPrint.INSTANCE.CP_Pos_ResetPrinter(h);
            AutoReplyPrint.INSTANCE.CP_Pos_SetMultiByteMode(h);
            AutoReplyPrint.INSTANCE.CP_Pos_SetMultiByteEncoding(h, AutoReplyPrint.CP_MultiByteEncoding_UTF8);
            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 1);
        }

        {
            AutoReplyPrint.INSTANCE.CP_Pos_SetAlignment(h, AutoReplyPrint.CP_Pos_Alignment_HCenter);
            AutoReplyPrint.INSTANCE.CP_Pos_SetTextScale(h, 1, 1);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString("\r\n" + title + "\r\n"));
            AutoReplyPrint.INSTANCE.CP_Pos_SetTextScale(h, 0, 0);

            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 2);
        }

        {
            AutoReplyPrint.INSTANCE.CP_Pos_SetHorizontalAbsolutePrintPosition(h, 30);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString(userName));
            AutoReplyPrint.INSTANCE.CP_Pos_SetHorizontalAbsolutePrintPosition(h, 240);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString(cardid + "\r\n"));
            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 1);
        }


        {
            AutoReplyPrint.INSTANCE.CP_Pos_SetAlignment(h, AutoReplyPrint.CP_Pos_Alignment_HCenter);
            AutoReplyPrint.INSTANCE.CP_Pos_SetTextScale(h, 1, 1);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString("\r\n" + queueName + "-" + number + "\r\n"));
            AutoReplyPrint.INSTANCE.CP_Pos_SetTextScale(h, 0, 0);
            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 2);
        }

        {
            AutoReplyPrint.INSTANCE.CP_Pos_SetAlignment(h, AutoReplyPrint.CP_Pos_Alignment_Left);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString("提示：\r\n"));
            AutoReplyPrint.INSTANCE.CP_Pos_SetPrintAreaLeftMargin(h, 0);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString(tips + "\r\n\r\n"));
            AutoReplyPrint.INSTANCE.CP_Pos_SetPrintAreaLeftMargin(h, 0);
            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 1);
        }
        {
            AutoReplyPrint.INSTANCE.CP_Pos_SetAlignment(h, AutoReplyPrint.CP_Pos_Alignment_HCenter);
            //            "http://weixin.qq.com/r/URGBmWTE_TmGrSD690RD"
            AutoReplyPrint.INSTANCE.CP_Pos_PrintQRCode(h, 2, AutoReplyPrint.CP_QRCodeECC_L, qrcodeUrl);
            AutoReplyPrint.INSTANCE.CP_Pos_FeedLine(h, 1);
            AutoReplyPrint.INSTANCE.CP_Pos_SetAlignment(h, AutoReplyPrint.CP_Pos_Alignment_Right);
            AutoReplyPrint.INSTANCE.CP_Pos_PrintTextInUTF8(h, new WString("\r\n取号时间：" + DateUtils.dateTimeNow() + "\r\n\r\n"));
        }

        {
            AutoReplyPrint.INSTANCE.CP_Pos_Beep(h, 2, 300);
            AutoReplyPrint.INSTANCE.CP_Pos_FeedAndHalfCutPaper(h);
        }
    }
}
